//
//  LgViewController.m
//  WeiDuYY
//
//  Created by 王克杨的Mac on 2019/1/23.
//  Copyright © 2019 W ke杨. All rights reserved.
//

#import "LgViewController.h"
#import "SDAutoLayout.h"
#import "ViewController.h"
#import "ZCViewController.h"
#import"FilmViewController.h"
#import "AFNetworking.h"
//#import "SHMD5Tool.h"
#import "NSString+AES.h"
@interface LgViewController (){
    //登录手机框
    UITextField *Phonetf;
    //登录手机密码
    UITextField *Passwordtf2;
    UIButton *btn;
}

@end

@implementation LgViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    //设置登录背景图片
    self.view.backgroundColor=[UIColor whiteColor];
    UIImageView *img=[[UIImageView alloc]initWithFrame:self.view.frame];
    img.image=[UIImage imageNamed:@"Bitmap"];
    img.frame=CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    [self.view addSubview:img];
    
    //手机号文本框
    Phonetf=[UITextField new];
    //设置提示文字的颜色
    Phonetf.placeholder = @"手机号";
    Phonetf.textColor=[UIColor lightGrayColor];
    [Phonetf setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [self.view addSubview:Phonetf];
    Phonetf.sd_layout.topSpaceToView(self.view, 200).leftSpaceToView(self.view, 100).widthIs(270).heightIs(50);
    
    //手机标识图
    UIImageView *img2=[UIImageView new];
    img2.image=[UIImage imageNamed:@"log_icon_phone_default_hdpi"];
    [self.view addSubview:img2];
    img2.sd_layout.topSpaceToView(self.view, 200).leftSpaceToView(self.view, 50).widthIs(24).heightIs(35);
    
    //设置手机号下面的灰色线
    UIView *vi=[UIView new];
    vi.backgroundColor=[UIColor lightGrayColor];
    [self.view addSubview:vi];
    vi.sd_layout.topSpaceToView(self.view, 250).leftSpaceToView(self.view,50).widthIs(300).heightIs(0.5);
    
    //登录密码文本框
    Passwordtf2=[UITextField new];
    Passwordtf2.placeholder=@"登录密码";
    Passwordtf2.textColor=[UIColor lightGrayColor];
    Passwordtf2.clearButtonMode=UITextFieldViewModeAlways;
    
    Passwordtf2.secureTextEntry=YES;
    [Passwordtf2 setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [self.view addSubview:Passwordtf2];
    Passwordtf2.sd_layout.topSpaceToView(vi, 20).leftSpaceToView(self.view, 100).widthIs(270).heightIs(50);
    
    //锁标识图
    UIImageView *img3=[UIImageView new];
    img3.image=[UIImage imageNamed:@"log_icon_lock_default_hdpi"];
    [self.view addSubview:img3];
    img3.sd_layout.topSpaceToView(vi, 20).leftSpaceToView(self.view, 50).widthIs(24).heightIs(35);
    
    //设置登录密码下面的灰色线
    UIView *vi2=[UIView new];
    vi2.backgroundColor=[UIColor lightGrayColor];
    [self.view addSubview:vi2];
    vi2.sd_layout.topSpaceToView(Passwordtf2, 0).leftSpaceToView(self.view, 50).widthIs(300).heightIs(0.5);
    
    //登录跳转按钮
    btn=[[UIButton alloc] init];
    btn.backgroundColor=[UIColor orangeColor];
    [btn setTitle:@"登录" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(ZZZ) forControlEvents:UIControlEventTouchUpInside];
    btn.layer.cornerRadius=15;
    btn.layer.masksToBounds=YES;
    [self.view addSubview:btn];
    btn.sd_layout.leftEqualToView(vi2).topSpaceToView(Passwordtf2, 200).widthIs(300).heightIs(40);

   
    //设置按钮勾选状态
    UIButton *checkbox = [UIButton buttonWithType:UIButtonTypeCustom];

    [checkbox setImage:[UIImage imageNamed:@"cb_glossy_off"] forState:UIControlStateNormal];
    [checkbox setImage:[UIImage imageNamed:@"cb_glossy_on"] forState:UIControlStateSelected];
    
    [checkbox addTarget:self action:@selector(checkboxClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:checkbox];
    checkbox.sd_layout.topSpaceToView(self.view, 330).leftSpaceToView(self.view, 48).widthIs(40).heightIs(40);
    
    //设置记住密码label
    UILabel *lab=[[UILabel alloc]init];
    lab.text=@"记住密码";
    lab.textColor=[UIColor whiteColor];
    [self.view addSubview:lab];
    lab.sd_layout.topSpaceToView(self.view, 330).leftSpaceToView(checkbox, 2).widthIs(100).heightIs(40);
    
    //设置快速注册按钮
   
    UIButton *btn2=[[UIButton alloc] init];
    [btn2 setTitle:@"快速注册" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn2 addTarget:self action:@selector(zhuce) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn2];
    btn2.sd_layout.topSpaceToView(self.view, 330).leftSpaceToView(lab, 75).widthIs(100).heightIs(40);
    
    //设置第三方快速登录label
    UILabel *lab2=[[UILabel alloc]init];
    lab2.text=@"-------------- 第三方登录 ------------";
    lab2.textColor=[UIColor whiteColor];
    [self.view addSubview:lab2];
    lab2.sd_layout.topSpaceToView(btn, 22).leftSpaceToView(self.view, 50).widthIs(300).heightIs(40);
    
    //设置第三方微信登录按钮
    UIButton *btn3=[[UIButton alloc]init];
    [btn3 setImage:[UIImage imageNamed:@"log_icon_weixin_default_hdpi"] forState:UIControlStateNormal];
    [self.view addSubview:btn3];
    [btn3 addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    btn3.sd_layout.topSpaceToView(self.view, 700).leftSpaceToView(self.view, 185).widthIs(40).heightIs(40);
    
}

//微信登录按钮方法
-(void)click{
    
}
//快速注册按钮的点击跳转方法
-(void)zhuce{
    ZCViewController *zc=[ZCViewController new];
    [self presentViewController:zc animated:YES completion:nil];
}
//勾选按钮的方法http://172.17.8.100/movieApi/movie/v1/findHotMovieList?sessionId=15486427733894677&userId=4677
-(void)checkboxClick:(UIButton *)btn
{
    btn.selected = !btn.selected;
}

//登录按钮的跳转方法
-(void)ZZZ{
    
    
    AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes=[NSSet setWithObject:@"text/html"];
    NSString *str= Phonetf.text;
    //密码
    NSString *str2= [Passwordtf2.text aci_encryptWithAES];
    
    NSDictionary *dic=@{@"phone":str,@"pwd":str2};
    [manager POST:@"http://172.17.8.100/movieApi/user/v1/login" parameters:dic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        //判断登录成功跳转
        if ([responseObject[@"status"] isEqualToString: @"0000"]) {
            ViewController *FF=[ViewController new];
            [self presentViewController:FF animated:YES completion:nil];
        }else{
            UIAlertController *alert =[UIAlertController alertControllerWithTitle:@"提示" message:@"账号或密码错误" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *action  = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            [alert addAction:action];
            [self presentViewController:alert animated:YES completion:nil];
        }

        NSLog(@"%@",responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@",error);
    }];
    
}


@end
